# sdl3_mixer cmake project-config input for CMakeLists.txt script

@PACKAGE_INIT@

include(FeatureSummary)
set_package_properties(SDL3_mixer PROPERTIES
    URL "https://www.libsdl.org/projects/SDL_mixer/"
    DESCRIPTION "SDL_mixer is a sample multi-channel audio mixer library"
)

set(SDL3_mixer_FOUND                ON)

set(SDLMIXER_VENDORED              @SDLMIXER_VENDORED@)

set(SDLMIXER_SNDFILE               @SDLMIXER_SNDFILE_ENABLED@)

set(SDLMIXER_FLAC                  @SDLMIXER_FLAC_ENABLED@)
set(SDLMIXER_FLAC_LIBFLAC          @SDLMIXER_FLAC_LIBFLAC_ENABLED@)
set(SDLMIXER_FLAC_DRFLAC           @SDLMIXER_FLAC_DRFLAC_ENABLED@)

set(SDLMIXER_GME                   @SDLMIXER_GME_ENABLED@)

set(SDLMIXER_MOD                   @SDLMIXER_MOD_ENABLED@)
set(SDLMIXER_MOD_MODPLUG           @SDLMIXER_MOD_MODPLUG_ENABLED@)
set(SDLMIXER_MOD_XMP               @SDLMIXER_MOD_XMP_ENABLED@)
set(SDLMIXER_MOD_XMP_LITE          @SDLMIXER_MOD_XMP_ENABLED@)

set(SDLMIXER_MP3                   @SDLMIXER_MP3_ENABLED@)
set(SDLMIXER_MP3_DRMP3             @SDLMIXER_MP3_DRMP3_ENABLED@)
set(SDLMIXER_MP3_MPG123            @SDLMIXER_MP3_MPG123_ENABLED@)

set(SDLMIXER_MIDI                  @SDLMIXER_MIDI_ENABLED@)
set(SDLMIXER_MIDI_FLUIDSYNTH       @SDLMIXER_MIDI_FLUIDSYNTH_ENABLED@)
set(SDLMIXER_MIDI_NATIVE           @SDLMIXER_MIDI_NATIVE_ENABLED@)
set(SDLMIXER_MIDI_TIMIDITY         @SDLMIXER_MIDI_TIMIDITY_ENABLED@)

set(SDLMIXER_OPUS                  @SDLMIXER_OPUS_ENABLED@)

set(SDLMIXER_VORBIS                @SDLMIXER_VORBIS_ENABLED@)
set(SDLMIXER_VORBIS_STB            @SDLMIXER_VORBIS_STB_ENABLED@)
set(SDLMIXER_VORBIS_TREMOR         @SDLMIXER_VORBIS_TREMOR_ENABLED@)
set(SDLMIXER_VORBIS_VORBISFILE     @SDLMIXER_VORBIS_VORBISFILE_ENABLED@)

set(SDLMIXER_WAVE                  @SDLMIXER_WAVE_ENABLED@)

set(SDLMIXER_WAVPACK               @SDLMIXER_WAVPACK_ENABLED@)

set(SDLMIXER_SDL3_REQUIRED_VERSION @SDL_REQUIRED_VERSION@)

set(SDL3_mixer_SDL3_mixer-shared_FOUND FALSE)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_mixer-shared-targets.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/SDL3_mixer-shared-targets.cmake")
    set(SDL3_mixer_SDL3_mixer-shared_FOUND TRUE)
endif()

set(SDL3_mixer_SDL3_mixer-static FALSE)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3_mixer-static-targets.cmake")

    if(SDLMIXER_VENDORED)
        if(SDLMIXER_GME)
            include(CheckLanguage)
            check_language(CXX)
            if(NOT CMAKE_CXX_COMPILER)
                message(WARNING "CXX language not enabled. Linking to SDL3_mixer::SDL3_mixer-static might fail.")
            endif()
        endif()
    else()
        set(_sdl_cmake_module_path "${CMAKE_MODULE_PATH}")
        list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

        include(CMakeFindDependencyMacro)
        include(PkgConfigHelper)

        if(NOT DEFINED CMAKE_FIND_PACKAGE_PREFER_CONFIG)
            set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
        endif()

        if(SDLMIXER_SNDFILE AND NOT TARGET SndFile::sndfile)
            find_dependency(SndFile)
        endif()

        if(SDLMIXER_FLAC_LIBFLAC AND NOT TARGET FLAC::FLAC)
            find_dependency(FLAC)
        endif()

        if(SDLMIXER_MOD_MODPLUG AND NOT TARGET modplug::modplug)
            find_dependency(modplug)
        endif()

        if(SDLMIXER_MOD_XMP AND NOT TARGET libxmp::libxmp)
            find_dependency(libxmp)
        endif()

        if(SDLMIXER_MOD_XMP_LITE AND NOT TARGET libxmp-lite::libxmp-lite)
            find_dependency(libxmp-lite)
        endif()

        if(SDLMIXER_MP3_MPG123 AND NOT TARGET MPG123::mpg123)
            find_dependency(mpg123)
        endif()

        if(SDLMIXER_MIDI_FLUIDSYNTH AND NOT TARGET FluidSynth::libfluidsynth)
            find_dependency(FluidSynth)
        endif()

        if(SDLMIXER_VORBIS_TREMOR AND NOT TARGET tremor::tremor)
            find_dependency(tremor)
        endif()

        if(SDLMIXER_VORBIS_VORBISFILE AND NOT TARGET Vorbis::vorbisfile)
            find_dependency(Vorbis)
        endif()

        if(SDLMIXER_OPUS AND NOT TARGET OpusFile::opusfile)
            find_dependency(OpusFile)
        endif()

        if(SDLMIXER_WAVPACK AND NOT TARGET WavPack::WavPack)
            find_dependency(wavpack)
        endif()

        set(CMAKE_MODULE_PATH "${_sdl_cmake_module_path}")
        unset(_sdl_cmake_module_path)

        if(HAIKU AND SDLMIXER_MIDI_NATIVE)
            include(CheckLanguage)
            check_language(CXX)
            if(NOT CMAKE_CXX_COMPILER)
                message(WARNING "CXX language not enabled. Linking to SDL3_mixer::SDL3_mixer-static might fail.")
            endif()
        endif()
    endif()

    include("${CMAKE_CURRENT_LIST_DIR}/SDL3_mixer-static-targets.cmake")
    set(SDL3_mixer_SDL3_mixer-static TRUE)
endif()

function(_sdl_create_target_alias_compat NEW_TARGET TARGET)
    if(CMAKE_VERSION VERSION_LESS "3.18")
        # Aliasing local targets is not supported on CMake < 3.18, so make it global.
        add_library(${NEW_TARGET} INTERFACE IMPORTED)
        set_target_properties(${NEW_TARGET} PROPERTIES INTERFACE_LINK_LIBRARIES "${TARGET}")
    else()
        add_library(${NEW_TARGET} ALIAS ${TARGET})
    endif()
endfunction()

# Make sure SDL3_mixer::SDL3_mixer always exists
if(NOT TARGET SDL3_mixer::SDL3_mixer)
    if(TARGET SDL3_mixer::SDL3_mixer-shared)
        _sdl_create_target_alias_compat(SDL3_mixer::SDL3_mixer SDL3_mixer::SDL3_mixer-shared)
    elseif(TARGET SDL3_mixer::SDL3_mixer-static)
        _sdl_create_target_alias_compat(SDL3_mixer::SDL3_mixer SDL3_mixer::SDL3_mixer-static)
    endif()
endif()

@PACKAGE_INIT@
check_required_components(SDL3_mixer)
